import java.io.IOException;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.SQLException;

import codeTools.MyDecoder;
import codeTools.MyEncoder;
import dbcTools.DBC_MySQL;
import dbcTools.DB_Operation;
import model.GroupMessageDBTO;
import model.User;
import model.UserDBTO;

public class Test {

	// 用戶表中需要填入的字段：头像avatar、昵称name、国家/地区address、手机号account、密码password、
	// 微信号wechat_number、是否已经设置一次微信号wechat_number_seted、创建时间creation_time。
	public static void main(String[] args) throws SQLException, IOException {
		DBC_MySQL mysql = new DBC_MySQL("config.xml");
		Connection connection = mysql.getConnection();

		System.out.println(connection);
		
		/**
		 * groupMessage
		 */
		/**
		 * insert
		 */
//		System.out.println(new GroupMessageDBTO(connection).addNewGroupMessage(1, 2, "String", "hello 世界。1"));
		/**
		 * delete
		 */
		System.out.println(new GroupMessageDBTO(connection).deleteGroupMessage(1, 1544419776868L));
		
		/**
		 * user
		 */
		/**
		 * insert
		 */
		//新增一条用户记录测试
//		 Blob blob = MyEncoder.pictureToBlob("1.jpg");
//		 System.out.println(new UserDBTO(connection).addNewUser(blob, "小龙", "上海", "119", "456789"));
		
		/**
		 * delete
		 */
		//根据id删除用户
//		System.out.println(new UserDBTO(connection).deleteUserById(connection, 20));
		
		//根据账号删除用户
//		System.out.println(new UserDBTO(connection).deleteUserByAccount(connection, "1190"));

		/**
		 * update
		 */
		//更新各个字段
//		UserDBTO userDBTO = new UserDBTO(connection);
//		userDBTO.setAutoCommit(false);
//		System.out.println(userDBTO.updateNameById(connection, "岸殇音1", 3));
//		System.out.println(userDBTO.updateGenderById(connection, "男", 3));
//		System.out.println(userDBTO.updateAddressById(connection, "深圳1", 3));
//		System.out.println(userDBTO.updateSignById(connection, "fight！1", 3));
//		System.out.println(userDBTO.updateAccountById(connection, "7771", 3));
//		System.out.println(userDBTO.updatePasswordById(connection, "4441", 3));
//		System.out.println(userDBTO.updateWechat_numberById(connection, "abc1", 3));
//		System.out.println(userDBTO.updateWechat_number_setedById(connection, true, 3));
//		userDBTO.commit();
		
		/**
		 * select
		 */
		//根据用户账号获取用户所有信息测试
//		UserDBTO userDBTO = new UserDBTO(connection);
//		User user = userDBTO.getUserById(connection, 3);
//		if(user != null) {
//			System.out.println(user.getName());
//			System.out.println(user.getAccount());
//			System.out.println(user.getPassword());
//			System.out.println(user.getCreation_time());
//			System.out.println(user.getWechat_number_seted());
//	
//			Blob blob = user.getAvatar();
//			MyDecoder.blobToPicture(blob, "D:\\3.jpg");
//		}else {
//			System.out.println("不存在此用户！");
//		}
		
		/**
		 * exists
		 */
		//根据用户账号判断此账号是否存在
//		System.out.println(new UserDBTO(connection).existUserByAccount(connection, "110"));
	}
	
	



	

	

	

}
